package com.enba.boot.mysql.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.enba.boot.core.base.ShowBootInfo;
import javax.annotation.PostConstruct;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisPlusStarterAutoConfiguration implements ShowBootInfo {

  /**
   * 配置MyBatis Plus拦截器，分页插件
   *
   * @return MyBatis Plus拦截器
   */
  @Bean
  public MybatisPlusInterceptor mybatisPlusInterceptor() {
    MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
    // 添加分页插件
    interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
    // 添加非法SQL拦截器（用于拦截和检查非法SQL，全表更新、删除操作，以及对索引的检查等）
    //    interceptor.addInnerInterceptor(new IllegalSQLInnerInterceptor());
    return interceptor;
  }

  /**
   * 自定义元数据处理器 字段填充
   *
   * @return MyMetaObjectHandler
   */
  @Bean
  public MyMetaObjectHandler myMetaObjectHandler() {
    return new MyMetaObjectHandler();
  }

  @PostConstruct
  @Override
  public void showBootInfo() {
    ShowBootInfo.moduleMap.put("enba-boot-starter-mysql", "enba-boot-starter-mysql模块集成成功");
  }
}
